package com.alibaba.nacos.example.spring.cloud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {

	@LoadBalanced
	@Bean
	public RestTemplate restTemplate() {
		return new RestTemplate();
	}

	@Autowired
	private RestTemplate restTemplate;
	
	@Autowired
	private TestFeignDemo testFeign;

//	public TestController(RestTemplate restTemplate) {
//		this.restTemplate = restTemplate;
//	}

	@RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
	public String echo(@PathVariable String str) {
		
		String restTemplateResult = restTemplate.getForObject("http://service-provider/hello/echo/" + str, String.class);
		System.err.println("restTemplateResult调用获取的结果:"+restTemplateResult);
		
		String feignResult = testFeign.echo(str);
		System.err.println("feign调用获取的结果:"+feignResult);
		
		return null;
	}
}